<template>
	<view class="content">
		<view class="info">
			<view class="list">
				<text class="text">
					保证金￥{{
						data.type == '2'
							? monthmom_price
							: data.type == '3'
							? channel_price
							: ''
					}}
				</text>
				<text class="text1">支付金额</text>
			</view>

			<view class="list1">
				<text class="text">支付方式</text>

				<u-radio-group v-model="value" @change="radioGroupChange" wrap>
					<u-radio
						@change="radioChange"
						v-for="(item, index) in list"
						:key="index"
						:name="item.name"
						:disabled="item.disabled"
						shape="square"
						active-color="#671729"
					>
						{{ item.name }}
					</u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="applyToSettleIn">
			<button type="default" @click="shengqing()">确认支付</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			
			monthmom_price: 0, // 月嫂认证金额
			channel_price: 0, //渠道认证金额
			data: {}, // 用户数据
			pay_method: 1, //支付方式

			list: [
				{
					name: '微信支付',
					disabled: false
				},
				{
					name: '线下支付',
					disabled: false
				}
			],
			//就会被默认选中
			value: '微信支付'
		};
	},
	methods: {
		// 选中某个单选框时，由radio时触发
		radioChange(e) {
			console.log('e :>> ', e);
			if (e === '微信支付') {
				this.pay_method = 1;
			} else {
				this.pay_method = 2;
			}
		},
		// 选中任一radio时，由radio-group触发
		radioGroupChange(e) {
			if (e === '微信支付') {
				this.pay_method = 1;
			} else {
				this.pay_method = 2;
			}
		},
		// 确认支付
		async shengqing() {
			const res = await this.$u.post(
				'/api/Allnews/attestationpay',
				{
					name: this.data.name,
					mobile: this.data.mobile,
					bank_card: this.data.bank_card,
					thumb: this.data.thumb,
					type: this.data.type,
					pay_method: this.pay_method,
					user_invitestr: this.data.user_invitestr,
					idcard: this.data.idcard,
					age: this.data.age,
					certificate: this.data.certificate,
				},
				{
					'XX-Token': uni.getStorageSync('token'),
					'XX-Device-Type': 'wxapp'
				}
			);
			console.log('确认支付  ', res);
			if (!res.data) {
				return uni.$showMsg(res.msg) 
				
			}
			this.ordersn = res.data.ordersn
			
			console.log('this.pay_method :>> ', this.pay_method);
			if (this.pay_method === 1) {
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: res.data.timeStamp,
					nonceStr: res.data.nonceStr,
					package: res.data.package,
					signType: res.data.signType,
					paySign: res.data.paySign,
					success: function(res) {
						console.log('success:' + JSON.stringify(res));
						uni.$showMsg('支付成功!');
						setTimeout(function() {
							uni.switchTab({
								url: '../my'
							});
						}, 1000);
						
					},
					fail: function(err) {
						console.log('fail:' + JSON.stringify(err));
						uni.$showMsg('支付失败!');
						
					}
				});
			} else {
				uni.$showMsg('支付成功!');
				setTimeout(function() {
					uni.switchTab({
						url: '../my'
					});
				}, 1000);
			}
		},
		//身份认证金额查询
		async amtQuery() {
			const res = await this.$u.post(
				'/api/User/rz_price',

				{
					'XX-Token': uni.getStorageSync('token'),
					'XX-Device-Type': 'wxapp'
				}
			);
			console.log('身份认证金额查询', res);
			this.monthmom_price = res.data.monthmom_price;
			this.channel_price = res.data.channel_price;
			console.log('this.monthmom_price :>> ', this.monthmom_price);
			console.log('this.channel_price :>> ', this.channel_price);
		},
		


	},
	onLoad(e) {
		this.data = JSON.parse(e.list);
		console.log('this.data:>> ', this.data);
		this.amtQuery();
		
	}
};
</script>

<style lang="scss">
.content {
	padding-top: 20rpx;
	.info {
		width: 690rpx;
		height: 447rpx;
		margin: 0 auto;
		background: #ffffff;
		border-radius: 20rpx;
		.list {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 63rpx;

			.text {
				// width: 190rpx;
				// height: 45rpx;
				font-size: 60rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ff0000;
			}
			.text1 {
				// width: 141px;
				// height: 34px;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.list1 {
			// display: flex;
			// flex-direction: column;
			padding: 71rpx 0 0 22rpx;
			.text {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}
	}
	.applyToSettleIn {
		button {
			margin-top: 404rpx;
			width: 690rpx;
			height: 100rpx;
			background: #671729;
			border-radius: 50rpx;

			font-size: 36rpx;
			font-family: 'Microsoft YaHei', PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
	}
}
</style>
